var mongoose = require('mongoose'),
    Schema   = mongoose.Schema,
    ObjectId = Schema.ObjectId;

const users = new Schema({
    name: String,
    pwd: String,
    mobile: String,
    createTime: Date,
    avatar: String,
    lastLoginTime: Date,
});

const sms = new Schema({
    mobile: String,
    type: String,
    time: Date,
    code: String,
    used: Boolean
});

const platforms = new Schema({
    platform: String, // 平台名称
    mobile: String,
    total: Number, // 手数
    inpoor: Number, // 入池率
    gains: Number, // 盈利
    winningRatio: Number, // 胜率
});

// 牌手档案
const profiles = new Schema({
    mobile: String,
    platform: String,
    inpoor_num: Number, // 入池手数
    inpoor_total: Number, // 入池总数
    winning_num: Number, // 胜局手数
    winning_total: Number, // 胜局总数
    doublePlay_num: Number, // 1v1 胜局手数
    doublePlay_total: Number, // 1v1 胜局总数
});

const accounts = new Schema({
    mobile: String,
    platform: String,
    status: Boolean,
    user: String,
    pwd: String,
    avatar: String,
    deleted: Boolean,
    userid: String,
    userName: String,
})

const tasks = new Schema({
    mobile: String,
    platform: String,
    user: String,
    taskId: String,
    finished: Boolean,
    time: Date,
    rounds: [
        {
            title: String,
            master: String,
            alliance: String,
            blind: String,
            date: String,
            duration: String,
            taskid: String,
            datetime: String,
            roundid: String
        }
    ]
    
})

const matchdatas = new Schema({
    rowid: String,
    platform: String,
    match_name: String,
    match_id: String,
    md5: String,
    date: Date,
    bssid: String,
    task: String,
    roundid: String, // 牌局id
    master: String, // 房主
    alliance: String, // 俱乐部
    title: String, // 牌局名
    userinfo: {
        userid: String,
        username: String,
        playerid: String
    },
    match: {
        preflop: {
            pot: Number,
            card: [String],
            sidepot: [
                {
                    playerId: String,
                    number: String
                }
            ],
            actions: [
                {
                    playerId: String,
                    action: String
                }
            ]
        },
        flop: {
            pot: Number,
            card: [String],
            sidepot: [
                {
                    playerId: String,
                    number: String
                }
            ],
            actions: [
                {
                    playerId: String,
                    action: String
                }
            ]
        },
        turn: {
            pot: Number,
            card: [String],
            sidepot: [
                {
                    playerId: String,
                    number: String
                }
            ],
            actions: [
                {
                    playerId: String,
                    action: String
                }
            ]
        },
        river: {
            pot: Number,
            card: [String],
            sidepot: [
                {
                    playerId: String,
                    number: String
                }
            ],
            actions: [
                {
                    playerId: String,
                    action: String
                }
            ]
        },
        showdown: {
            player: [
                {
                    // playerId: String,
                    action: String,
                    card: [String],
                    number: String,
                    seatNumber: Number,
                    // status: Number
                }
            ]
        },
        showcard: {
            player: [
                {
                    // playerId: String,
                    card: {},
                }
            ]
        },
        table: {
            seat: [
                {
                    name: String,
                    playerId: String,
                    chips: String,
                    seatNumber: String,
                    avatar: String
                }
            ],
            sb: {
                chips: String,
                number: Number
            },
            bb: {
                chips: String,
                number: Number
            },
            ante: [
                {
                    playerId: {},
                    action: {},
                }
            ],
            dealer: Number
        }
    }
});

module.exports = {
    users: users,
    platforms: platforms,
    profiles: profiles,
    sms: sms,
    accounts: accounts,
    matchdatas: matchdatas,
    tasks: tasks
}
